<template>
  <panel title="硬盘" v-if="current">
    <div class="content">
      <div class="text-center">
        <p class="font-bold">总计</p>
        <p v-text="prettyBytes(current.total)" />
      </div>
      <div class="text-center">
        <p class="font-bold">可用</p>
        <p v-text="prettyBytes(current.free)" />
      </div>
      <div class="text-center">
        <p class="font-bold">阈值</p>
        <p v-text="prettyBytes(current.threshold)" />
      </div>
    </div>
  </panel>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import panel from './panel.vue';
import api from "@/http/api";
import prettyBytes from 'pretty-bytes';

const current = ref(null);

const fetchMetrics = async() => {
  const res = await api.get('/actuator/health');
  current.value = res.data.components?.diskSpace?.details || {};
};

onMounted(() => {
  fetchMetrics();
});
</script>

<style scoped>
.content {
  display: flex;
  flex-direction: row;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  -webkit-box-pack: justify;
  -ms-flex-pack: justify;
  justify-content: space-between;
  .text-center {
    text-align: center;
    flex-grow: 1;
  }
  .font-bold {
    margin-bottom: 5px;
  }
}
</style>
